﻿using SYJ.Common.Log;
using SYJ.Common.web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace SYJ.Common.Filters
{
    public class HandlerErrorAttribute : HandleErrorAttribute
    {
        public override void OnException(ExceptionContext context)
        {
            base.OnException(context);
            //记录处理错误消息
            //var log = LogFactory.GetLogger(context.Controller.ToString());
            //log.Error(context.Exception);
            //页面跳转到错误页面
           // context.HttpContext.Response.Redirect("/Error.html");
            context.ExceptionHandled = true;
            context.HttpContext.Response.StatusCode = 200;
            context.Result = new ContentResult { Content = new AjaxResult { state = ResultType.error.ToString(), message = context.Exception.Message }.ToJson() };
        }
        private void WriteLog(ExceptionContext context)
        {
            if (context == null)
                return;
            var log = LogFactory.GetLogger(context.Controller.ToString());
            log.Error(context.Exception);
        }
    }
}
